#ifndef SERIALH_H
#define SERIALH_H


#include <QMutex>
#include <QThread>
#include <QObject>
#include "content/BoostControl.h"
#include "content/QSerialControl.h"
#include "content/ModbusControl.h"

#include <memory>

namespace Serial {
    typedef enum Control_Tag{
        BOOST_MODE =(0u),
        QT_MODE ,
        MODBUS,
        TAG_ALL
    }REQUEST_MODE;
    // static Serial::REQUEST_MODE current_mode =  Serial::QT_MODE; /// Serial::QT_MODE;
    static Serial::REQUEST_MODE current_mode =  Serial::BOOST_MODE; /// Serial::QT_MODE;
}






class SerialHelper{

    SerialHelper(){
        init();
    }



public:

    static SerialHelper* GetInstance(){
        static QMutex mutex;
        static QScopedPointer<SerialHelper> inst;
        if (Q_UNLIKELY(!inst)) {
            mutex.lock();
            if (!inst) {
                inst.reset(new SerialHelper);
            }
            mutex.unlock();
        }
        return inst.data();
    }

    /// 获取内部成员指针
    std::shared_ptr<SerialBase> p() {
        return mySerial;
    }


    //boost::signals2::signal<void(std::string)> _sigUpdate;

private:
    static std::shared_ptr<SerialBase> mySerial ;


private:

    void init(){

        switch (Serial::current_mode) {
        case Serial::BOOST_MODE:
            mySerial.reset(new BoostControl);
            break;
        case Serial::QT_MODE:
            mySerial.reset(new QSerialControl);
            break;
        case Serial::MODBUS:
            mySerial.reset(new ModbusControl);
            break;
        default:
            mySerial.reset(new SerialBase);
            break;
        }
        //mySerial.get()->_sigUpdate.connect(_sigUpdate);
    }

};


#endif // SERIALH_H
